package com.chanzany.principle.ocp.improve;

public class Ocp {
    public static void main(String[] args) {
        GraphicEditor graphicEditor = new GraphicEditor();
        graphicEditor.drawShape(new Rectangle());
        graphicEditor.drawShape(new Circle());
        graphicEditor.drawShape(new Triangle());
    }
}
abstract class Shape{
    final String type = "几何形状"; //闭合原则---final
    public abstract void draw();  //开放原则--接口or抽象方法
}
class Rectangle extends Shape{
    @Override
    public void draw() {
        System.out.println("绘制矩形");
    }
}
class Circle extends Shape{
    @Override
    public void draw() {
        System.out.println("绘制圆形");
    }
}
//新增画三角形
class Triangle extends Shape{
    @Override
    public void draw() {
        System.out.println("绘制三角形");
    }
}
//这是一个用于绘图的类
class GraphicEditor{
    public void drawShape(Shape s){
       s.draw();
    }
}
